package com.mhwx.mhlive.ui.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.mhwx.mhlive.R;
import com.mhwx.mhlive.ui.activity.PersonalHomepage;
import com.mhwx.mhlive.ui.base.BaseAdapter;
import com.mhwx.mhlive.ui.widget.CircleImageView;
import com.mhwx.mhlive.util.IntoActivity;

import java.util.List;



/**
 * 类功能描述
 *
 * @author Guol
 * @version 1.0
 * @copyright 北京明华维新信息技术有限公司
 * @time 2017/5/3
 */
public class GridViewAdapter extends BaseAdapter {
    private Context context;
    private List<String> list;
    public GridViewAdapter(Context context, List<String> list) {
         this.context=context;
        this.list=list;
    }

    public void setData(List<String> list){
        this.list=list;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder  holder=null;
        if (convertView==null){
            holder=new ViewHolder ();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_grid_hear, null);
            holder.circleImageView = (CircleImageView) convertView.findViewById(R.id.img_hear);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder)convertView.getTag();
        }
        holder.circleImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i("TAG",position+"");
                IntoActivity.toNextActivity(context,PersonalHomepage.class);
            }
        });

        return convertView;
    }

public class ViewHolder  {
    public CircleImageView circleImageView;

}
}
